package asteroids.model.programs.parsing.statements;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.programs.parsing.expressions.E;

public class WhileLoop extends CollectionStatement {
	public WhileLoop(int line, int column, E condition, S body) {
		super(line, column, body);
		setCondition(condition);
	}


	public void setCondition(E condition){
		this.condition = condition;
	}

	public E getCondition(){
		return condition;
	}
	public boolean isGoodCondition(Map<String,E> map, CollisionObject collisionObject){
		if(getCondition().isBoolean()){
			return true;
		}
		if(getCondition().isString()){
			if(getCondition().getContent(map, collisionObject).getClass() == Boolean.class){
				return true;
			}
		}
		return false;
	}

	private E condition;
	
	@Override
	public void execute(ExecuteManager executeManager) {
		executeManager.execute(this);
	}
	public void redo(){
		super.redo();
		getBody().redo();
	}

}
